<title>The enum statement</title>
<head>
<script language="JavaScript">
</script>
</head>
<body bgcolor="#ffffcc">
<hr>
<center>
<h1>The enum statement</h1>
</center>
<hr>
<p>
ENUM is closely related to the <a href="define_preprocessor.html">#define</a>
preprocessor.<p>
It allows you to define a list of aliases which represent integer numbers. For
example if you find yourself coding something like:
<pre>
        #define MON 1 
        #define TUE 2 
        #define WED 3 
</pre>
You could use <b>enum</b> as below.
<pre>
        enum week { Mon=1, Tue, Wed, Thu, Fri Sat, Sun} days;
  or
        enum escapes { BELL   = '\a', BACKSPACE = '\b', HTAB = '\t',
                       RETURN = '\r', NEWLINE   = '\n', VTAB = '\v' };
                       
  or     
        enum boolean { FALSE = 0, TRUE };
 
</pre>

An advantage of <b>enum</b> over <b>#define</b> is that it has 
<a href="../glossary.html#scope">scope</a>
This means that the variable (just like any other) is only visable 
within the block it was declared within.
<p>
<hr>
<h2>Notes:</h2>
<ul>
<li>If a variable is 
<a href="../glossary.html#definition">defined</a>
with <b>enum</b> it is considered by
the compiler to be an integer, and can have ANY integer value assigned
to it, it is not restericted to the values in the enum statement.
</ul>


<hr>
<h2>See Also:</h2>

<a href=../../CPLUSPLUS/SYNTAX/enum.html> C++ Enhancements to enum.</a><p>
<a href=define_preprocessor.html>#define</a> preprocessor.<p>

<hr>
<h2>Examples:</h2>

<a href="../EXAMPLES/enum1.c"><img src="../../GRAPHICS/computer.gif"></a>
enum example 1.<p>
<a href="../EXAMPLES/enum2.c"><img src="../../GRAPHICS/computer.gif"></a>
enum example 2.<p>

<a href="../EXAMPLES/enum3.c"><img src="../../GRAPHICS/computer.gif"></a>
enum coding error.<p>

<a href="../EXAMPLES/enum4.c"><img src="../../GRAPHICS/computer.gif"></a>
Another enum coding error.<p>

<a href="../EXAMPLES/enum5.c"><img src="../../GRAPHICS/computer.gif"></a>
enum and #define coding error.<p>

<p>

<hr>
<p>
<center>
<table border=2 width="80%" bgcolor="ivory">
<tr align=center>
<td width="25%">
<a href="../cref.html">                  Top</a>
</td><td width="25%">
<a href="../master_index.html">          Master Index</a>
</td><td width="25%">
<a href="keywords.html">                 Keywords</a>
</td><td width="25%">
<a href="../FUNCTIONS/funcref.htm">      Functions</a>
</td>
</tr>
</table>
</center>
<p>
<hr>
<address><a href="../../address.html">Martin Leslie</a> 
</address><p>
</body>
</html>
